<template>  
    <div class="goods_list">
        <!-- <router-link class="goods_item" :to="'/home/goodsInfo/'+item.id" tag="div" v-for="item in goodsList" :key="item.id">
            <img :src="item.img">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">{{item.price1}}元</span>
                    <span class="old">{{item.price2}}</span>
                </p>
                <p class="cell">
                    <span>{{item.goodsStatus}}</span>
                    <span>剩余{{item.after}}件</span>
                </p>
            </div>
        </router-link>  -->

        <div class="goods_item" @click="goGoodsInfo(item.id)" v-for="item in goodsList" :key="item.id">
            <img :src="item.img">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">{{item.price1}}元</span>
                    <span class="old">{{item.price2}}</span>
                </p>
                <p class="cell">
                    <span>{{item.goodsStatus}}</span>
                    <span>剩余{{item.after}}件</span>
                </p>
            </div>
        </div> 
        <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>
<script>
export default {
    data(){
        return {
            pageindex:1,
            goodsList:[]
        }
    },
    created(){
        this.getGoodsList()
    },
    methods:{
        getGoodsList(){
            this.$http.get("../mydata/goodsList/1.json?pageindex="+this.pageindex).then(result=>{
                if(result.body.status===0){ 
                    this.goodsList = this.goodsList.concat(result.body.message);
                }
            });
        },
        getMore(){
            this.pageindex++;
            this.getGoodsList();
        },
        goGoodsInfo(id){
            // this.$router.push("/home/goodsInfo/"+id);
            // this.$router.push({path:'/home/goodsInfo/'+id});
            this.$router.push({name:'goodsInfo',params:{id}});
        }
    }
}
</script>
<style scoped>
.goods_list{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 7px;
}
.goods_list>.goods_item{
    width: 49%;
    border:1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin: 5px 0;
    flex-direction: column;
    justify-content: space-between;
    padding: 2px;
    height: 175px;
}
.goods_list>.goods_item>img{
    width: 100%;
}
.goods_list>.goods_item>.title{
    font-size: 14px;
}
.goods_list>.goods_item>.info{
    background-color: #eee;
}
.goods_list>.goods_item>.info>p{
    margin: 0;
}
.goods_list>.goods_item>.info .now{
    color: red;
    font-weight: bold;
    font-size: 16px;
}
.goods_list>.goods_item>.info .old{
    margin-left: 10px;
    font-size: 12px;
    text-decoration: line-through;
}
.goods_list>.goods_item>.info>.cell{
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}
</style>

